package action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import biz.DepartBiz;
import entity.Depart;

/**
 * @author 陈彬彬
 * @publish 2015-11-17 下午8:46:37
 * @category 部门控制层类
 */
@Controller
public class DepartAction extends BaseAction {
	@Resource
	private DepartBiz biz;
	
	private Depart dep;
	private List<Depart> deps;
	public Depart getDep() {
		return dep;
	}
	public void setDep(Depart dep) {
		this.dep = dep;
	}
	public List<Depart> getDeps() {
		return deps;
	}
	public void setDeps(List<Depart> deps) {
		this.deps = deps;
	}
	//增
	public String add(){
		if(biz.add(dep)){
			this.setMsg("添加部门成功");	
			dep=null;
		}else{
			this.setMsg("添加部门失败");		
		}
		return "edit";
	}
	//删
	public String del(){
		if(biz.del(getId())){
			this.setMsg("删除部门成功！");
		}else{
			this.setMsg("删除部门失败！");
		}
		return list();
	}
	//改
	public String update(){
		if(biz.update(dep)){
			this.setMsg("更新部门成功！");
			return list();
		}else{
			this.setMsg("更新部门失败！");
			return "edit";
		}
	}
	//查
	public String list(){
		deps=biz.queryByPage(getPage(), 5);
		int count=biz.count();
		setTpage(count%5==0?count/5:(count/5+1));
		return "list";
	}
	
	public String show(){
		dep=biz.get(getId());
		if(dep==null){
			setMsg("该部门不存在！");
			return list();
		}
		return "edit";
	}
}
